package com.csy.client_server.client_side;


import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

import com.csy.chat.chat_message;

//客户端读取服务器端信息的线程
public class ClientReadServer implements Runnable
{
    private Socket socket;
    private StringBuffer msg=new StringBuffer("");
    private chat_message temp;
    public ClientReadServer(Socket socket)
    {
        this.socket=socket;
    }
    @Override
    public void run()
    {
        //获取服务器端输入流
        try
        {
            Scanner scanner=new Scanner(socket.getInputStream());
            while(scanner.hasNext())
            {
                String mag=scanner.next();
                String mag2=scanner.next();
                String mag3=scanner.next();
//                mag=mag.replace('`',' ');
                temp=new chat_message(mag,mag2,mag3);
                if(mag.equals(" "))
                    System.out.println("1");
                else {
                    System.out.println(mag);
                }
                msg.append(mag);
            }
            scanner.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
    public chat_message getMsg()
    {
        chat_message temp2=new chat_message(temp);
        temp.clean();
        return temp2;
    }

}

